from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-12 14:02:15.660442
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 12, Nov, 2022
Time: 14:02:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9247
Nobs: 838.000 HQIC: -51.2380
Log likelihood: 10938.7 FPE: 4.60301e-23
AIC: -51.4328 Det(Omega_mle): 4.13691e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298907 0.050731 5.892 0.000
L1.Burgenland 0.109802 0.034864 3.149 0.002
L1.Kärnten -0.106189 0.018571 -5.718 0.000
L1.Niederösterreich 0.210980 0.072915 2.893 0.004
L1.Oberösterreich 0.099891 0.069361 1.440 0.150
L1.Salzburg 0.251856 0.036970 6.812 0.000
L1.Steiermark 0.036150 0.048517 0.745 0.456
L1.Tirol 0.107647 0.039291 2.740 0.006
L1.Vorarlberg -0.060020 0.033876 -1.772 0.076
L1.Wien 0.055186 0.062144 0.888 0.375
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067638 0.104660 0.646 0.518
L1.Burgenland -0.030875 0.071926 -0.429 0.668
L1.Kärnten 0.047574 0.038312 1.242 0.214
L1.Niederösterreich -0.174037 0.150427 -1.157 0.247
L1.Oberösterreich 0.379738 0.143095 2.654 0.008
L1.Salzburg 0.288505 0.076270 3.783 0.000
L1.Steiermark 0.107199 0.100092 1.071 0.284
L1.Tirol 0.315662 0.081059 3.894 0.000
L1.Vorarlberg 0.022960 0.069888 0.329 0.743
L1.Wien -0.017976 0.128205 -0.140 0.888
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197169 0.026261 7.508 0.000
L1.Burgenland 0.092439 0.018047 5.122 0.000
L1.Kärnten -0.008794 0.009613 -0.915 0.360
L1.Niederösterreich 0.267768 0.037744 7.094 0.000
L1.Oberösterreich 0.115224 0.035904 3.209 0.001
L1.Salzburg 0.052531 0.019137 2.745 0.006
L1.Steiermark 0.016298 0.025114 0.649 0.516
L1.Tirol 0.098389 0.020339 4.838 0.000
L1.Vorarlberg 0.056197 0.017536 3.205 0.001
L1.Wien 0.113829 0.032168 3.539 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105037 0.026909 3.903 0.000
L1.Burgenland 0.047347 0.018493 2.560 0.010
L1.Kärnten -0.017112 0.009850 -1.737 0.082
L1.Niederösterreich 0.197212 0.038676 5.099 0.000
L1.Oberösterreich 0.280909 0.036791 7.635 0.000
L1.Salzburg 0.120711 0.019610 6.156 0.000
L1.Steiermark 0.102366 0.025735 3.978 0.000
L1.Tirol 0.123097 0.020841 5.906 0.000
L1.Vorarlberg 0.068945 0.017969 3.837 0.000
L1.Wien -0.029334 0.032962 -0.890 0.374
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129855 0.048764 2.663 0.008
L1.Burgenland -0.049380 0.033512 -1.473 0.141
L1.Kärnten -0.039609 0.017851 -2.219 0.026
L1.Niederösterreich 0.165867 0.070088 2.367 0.018
L1.Oberösterreich 0.139948 0.066672 2.099 0.036
L1.Salzburg 0.285096 0.035536 8.023 0.000
L1.Steiermark 0.033619 0.046636 0.721 0.471
L1.Tirol 0.163359 0.037768 4.325 0.000
L1.Vorarlberg 0.103819 0.032563 3.188 0.001
L1.Wien 0.069135 0.059734 1.157 0.247
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059145 0.038628 1.531 0.126
L1.Burgenland 0.042667 0.026546 1.607 0.108
L1.Kärnten 0.049761 0.014140 3.519 0.000
L1.Niederösterreich 0.228323 0.055519 4.113 0.000
L1.Oberösterreich 0.271614 0.052813 5.143 0.000
L1.Salzburg 0.058350 0.028150 2.073 0.038
L1.Steiermark -0.007613 0.036942 -0.206 0.837
L1.Tirol 0.156426 0.029917 5.229 0.000
L1.Vorarlberg 0.068017 0.025794 2.637 0.008
L1.Wien 0.073843 0.047317 1.561 0.119
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183829 0.046230 3.976 0.000
L1.Burgenland -0.004089 0.031770 -0.129 0.898
L1.Kärnten -0.060846 0.016923 -3.595 0.000
L1.Niederösterreich -0.085906 0.066446 -1.293 0.196
L1.Oberösterreich 0.192699 0.063207 3.049 0.002
L1.Salzburg 0.059300 0.033690 1.760 0.078
L1.Steiermark 0.226726 0.044212 5.128 0.000
L1.Tirol 0.494641 0.035805 13.815 0.000
L1.Vorarlberg 0.047605 0.030870 1.542 0.123
L1.Wien -0.052056 0.056630 -0.919 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158760 0.052657 3.015 0.003
L1.Burgenland -0.009502 0.036187 -0.263 0.793
L1.Kärnten 0.064797 0.019276 3.362 0.001
L1.Niederösterreich 0.203667 0.075683 2.691 0.007
L1.Oberösterreich -0.067926 0.071994 -0.943 0.345
L1.Salzburg 0.223426 0.038373 5.822 0.000
L1.Steiermark 0.112976 0.050358 2.243 0.025
L1.Tirol 0.084110 0.040782 2.062 0.039
L1.Vorarlberg 0.122132 0.035162 3.473 0.001
L1.Wien 0.109182 0.064502 1.693 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356419 0.030967 11.510 0.000
L1.Burgenland 0.008857 0.021281 0.416 0.677
L1.Kärnten -0.024364 0.011336 -2.149 0.032
L1.Niederösterreich 0.229924 0.044508 5.166 0.000
L1.Oberösterreich 0.159914 0.042339 3.777 0.000
L1.Salzburg 0.053990 0.022567 2.392 0.017
L1.Steiermark -0.017423 0.029615 -0.588 0.556
L1.Tirol 0.116521 0.023984 4.858 0.000
L1.Vorarlberg 0.071443 0.020678 3.455 0.001
L1.Wien 0.045785 0.037933 1.207 0.227
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043719 0.160739 0.193075 0.166126 0.131592 0.124315 0.069952 0.231425
Kärnten 0.043719 1.000000 0.001701 0.131850 0.045168 0.099520 0.428219 -0.050801 0.102168
Niederösterreich 0.160739 0.001701 1.000000 0.346081 0.166539 0.311667 0.127764 0.192184 0.341603
Oberösterreich 0.193075 0.131850 0.346081 1.000000 0.235731 0.341642 0.178010 0.180379 0.274899
Salzburg 0.166126 0.045168 0.166539 0.235731 1.000000 0.153679 0.145210 0.153042 0.141100
Steiermark 0.131592 0.099520 0.311667 0.341642 0.153679 1.000000 0.163587 0.148825 0.093369
Tirol 0.124315 0.428219 0.127764 0.178010 0.145210 0.163587 1.000000 0.121875 0.163477
Vorarlberg 0.069952 -0.050801 0.192184 0.180379 0.153042 0.148825 0.121875 1.000000 0.018123
Wien 0.231425 0.102168 0.341603 0.274899 0.141100 0.093369 0.163477 0.018123 1.000000